﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using AmuTools;
using app.Api;

namespace app.Models
{
    [Model(TableName = "t_abutment", PrimaryKey = "id", IdentityInsert = true)]
    public class Abutment
    {
        public int id { get; set; }

        public string sponsor { get; set; } // 发起者

        public string finance_member_id { get; set; }

        private Member _finance_member = null;
        [Field(Storageable = false)]
        public Member finance_member
        {
            get
            {
                if (_finance_member == null)
                {
                    _finance_member = G.DB.GetById<Member>(finance_member_id);
                }
                return _finance_member;
            }
        }

        public string investment_member_id { get; set; }

        private Member _investment_member = null;
        [Field(Storageable = false)]
        public Member investment_member
        {
            get
            {
                if (_investment_member == null)
                {
                    _investment_member = G.DB.GetById<Member>(investment_member_id);
                }
                return _investment_member;
            }
        }

        public string finance_id { get; set; } // 融资项目ID

        private Finance _finance = null;
        [Field(Storageable = false)]
        public Finance finance
        {
            get
            {
                if(_finance == null)
                {
                    _finance = G.DB.GetById<Finance>(finance_id);
                }
                return _finance;
            }
        }

        public string investment_id { get; set; } // 投资项目ID，可能没有

        private Investment _investment = null;
        [Field(Storageable = false)]
        public Investment investment
        {
            get
            {
                if (_investment == null && investment_id != "")
                {
                    _investment = G.DB.GetById<Investment>(investment_id);
                }
                return _investment;
            }
        }

        [Field(DataType = "char(13)")]
        public string create_time { get; set; }
        
        public int finance_status { get; set; }

        public int investment_status { get; set; }

        [Field(Webable = false)]
        public int is_delete { get; set; }

        public static Abutment[] GetInitData()
        {
            return new Abutment[]{
                // 投资者发起的投递
                new Abutment {
                    sponsor = ROLE_TYPES.Investor,
                    finance_id = "1",
                    finance_member_id = "200002",
                    finance_status = 0,
                    investment_id = "1",
                    investment_member_id = "200001",
                    investment_status = 1
                },
                // 融资者发起的约谈
                new Abutment {
                    sponsor = ROLE_TYPES.Financier,
                    finance_id = "1",
                    finance_member_id = "200002",
                    finance_status = 1,
                    investment_id = "1",
                    investment_member_id = "200001",
                    investment_status = 0
                }
            };
        }
    }
    
    enum ABUTMENT_STATUS
    {
        NONE = 0, // 未操作
        INTERVIEW = 1, // 约谈
        AGREE = 2, // 同意
        CANCEL = 3 // 取消
    }
}
